<template>
  <div>
    <a-card :bordered="false">
      <f-search-form :more="false" @searchHandler="searchHandler">
        <f-search-form-item label="标题" name="videoTitle"/>
      </f-search-form>
      <f-table ref="table" size="default" :scroll="scroll" rowKey="videoId" :columns="columns" :multiple="false" :operator="operator" :params="queryParam" :api="api.avmVideo">
        <span slot="videoTitle" slot-scope="text, record, index">
             <f-elipsis :text="record.videoTitle"></f-elipsis>
        </span>
        <span slot="coverImage" slot-scope="text, record, index">
           <f-images :value="record.coverImage"></f-images>
        </span>
        <span slot="sendStatus" slot-scope="text, record, index">
          <a-switch v-model="record.videoState==1" checkedChildren="已发布" unCheckedChildren="未发布" @change="(checked) => setStatus(checked,record)"/>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.modal.handleShow(record)">编辑</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.remove(record.videoId)">删除</a>
              </a-menu-item>
              <a-menu-item>
                <a href="javascript:;" @click="lookComment(record.videoId)">查看评论</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <video-drawer ref="modal"></video-drawer>
      <comment-drawer ref="commentModal" :contentId="nowVideoId" :commentType="3" title="视频评论"></comment-drawer>
    </a-card>
  </div>
</template>

<script>

  import VideoDrawer from './video_drawer'
  import CommentDrawer from '../../comment/comment_drawer'

  export default {
    name: 'TableList',
    components: {
      VideoDrawer,
      CommentDrawer
    },
    data() {
      let me = this
      return {
        //列表初始化查询参数
        queryParam: {},
        nowVideoId: '',
        scroll: { x: 1350 },
        // 表头
        columns: [
          {
            title: '#',
            width: '60',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '封面图',
            align: 'center',
            scopedSlots: { customRender: 'coverImage' }
          },
          {
            title: '标题',
            dataIndex: 'videoTitle',
            scopedSlots: { customRender: 'videoTitle' }
          },
          {
            title: '标签',
            align: 'center',
            width: '160px',
            dataIndex: 'videoTag'
          },
          {
            title: '发布人',
            dataIndex: 'nickName'
          },
          {
            title: '发布地址',
            width: '260px',
            dataIndex: 'sendAddress'
          },
          {
            title: '评论数量',
            dataIndex: 'commentNum'
          },
          {
            title: '发布状态',
            align: 'center',
            fixed: 'right',
            dataIndex: 'contentState',
            scopedSlots: { customRender: 'sendStatus' }
          },
          {
            title: '操作',
            fixed: 'right',
            dataIndex: 'action',
            scopedSlots: { customRender: 'action' }
          }
        ],
        //操作按钮
        operator: [
          {
            name: '删除',
            icon: 'delete',
            batch: true,
            handler: function(table) {
              table.remove()
            }
          }
        ]
      }
    },
    created() {

    },
    methods: {
      setStatus(check, record) {
        this.http.post(this, {
          url: this.api.avmVideo.setState,
          data: {
            ids: record.videoId,
            videoState: Number(check)
          },
          success(me, data) {
            record.videoState = data
          }
        })
      },
      lookComment(videoId) {
        this.nowVideoId = videoId
        this.$refs.commentModal.handleShow()
      }
    }
  }
</script>
